package com.pearadmin.modules.sys.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.modules.sys.domain.InvAnode;
import com.pearadmin.modules.sys.domain.vo.InvAnodeVO;
import com.pearadmin.modules.sys.mapper.InvAnodeMapper;
import com.pearadmin.modules.sys.service.IInvAnodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 阳极库存Service业务层处理
 *
 * @author Mr.Ling
 * @date 2021-11-26
 */
@Service
public class InvAnodeServiceImpl implements IInvAnodeService {
    @Autowired
    private InvAnodeMapper invAnodeMapper;

    /**
     * 查询阳极库存
     *
     * @param id 阳极库存ID
     * @return 阳极库存
     */
    @Override
    public InvAnode selectInvAnodeById(String id) {
        return invAnodeMapper.selectInvAnodeById(id);
    }

    @Override
    public InvAnode selectInvAnodeByAnodeCode(String anodeCode) {
        return invAnodeMapper.selectInvAnodeByAnodeCode(anodeCode);
    }

    /**
     * 查询阳极库存列表
     *
     * @param invAnode 阳极库存
     * @return 阳极库存
     */
    @Override
    public List<InvAnode> selectInvAnodeList(InvAnode invAnode) {
        return invAnodeMapper.selectInvAnodeList(invAnode);
    }

    /**
     * 查询阳极库存
     * @param invAnode 阳极库存
     * @param pageDomain
     * @return 阳极库存 分页集合
     * */
    @Override
    public PageInfo<InvAnode> selectInvAnodePage(InvAnode invAnode, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<InvAnode> data = invAnodeMapper.selectInvAnodeList(invAnode);
        return new PageInfo<>(data);
    }

    /**
     * 新增阳极库存
     *
     * @param invAnode 阳极库存
     * @return 结果
     */

    @Override
    public int insertInvAnode(InvAnode invAnode) {
        return invAnodeMapper.insertInvAnode(invAnode);
    }

    /**
     * 修改阳极库存
     *
     * @param invAnode 阳极库存
     * @return 结果
     */
    @Override
    public int updateInvAnode(InvAnode invAnode) {
        return invAnodeMapper.updateInvAnode(invAnode);
    }

    /**
     * 删除阳极库存对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteInvAnodeByIds(String[] ids) {
        return invAnodeMapper.deleteInvAnodeByIds(ids);
    }

    /**
     * 删除阳极库存信息
     *
     * @param id 阳极库存ID
     * @return 结果
     */
    @Override
    public int deleteInvAnodeById(String id) {
        return invAnodeMapper.deleteInvAnodeById(id);
    }

    /**
     * 配送工单获取最新库存阳极的信息
     * @param anodeCode
     * @return
     */
    @Override
    public InvAnodeVO findAnodeCode(String anodeCode) {
        return invAnodeMapper.findAnodeCode(anodeCode);
    }

    @Override
    public List<InvAnode> getCastingDetailById(String castingId) {
        return invAnodeMapper.getCastingDetailById(castingId);
    }

    @Override
    public boolean checkAnodeCodeIsValid(String anodeCode) {
        List<String> strings = invAnodeMapper.checkAnodeCodeIsValid();
        if (CollectionUtil.isEmpty(strings)) {
            return true;
        } else {
            List<String> collect = strings.stream().filter(e -> e.equals(anodeCode)).collect(Collectors.toList());
            return CollectionUtil.isEmpty(collect);
        }
    }

    @Override
    public int selectCurrNum(String blockType) {
        return invAnodeMapper.selectCurrNum(blockType);
    }

}
